package com.kafka.demo;


import kafka.producer.KeyedMessage;
import kafka.producer.Producer;
import kafka.producer.ProducerConfig;
import scala.collection.Seq;

import java.util.Properties;

/**
 * =================================
 * <p>
 * Created by cjj on 2018/10/17.
 * <p>
 * 描述: 生产者
 */

public class ProducerDemo {


    public static void main(String[] args) throws InterruptedException {

        Properties properties = new Properties();

        properties.setProperty("zk.connect","cj.sun.hadoop1:2181,cj.sun.hadoop2:2181");
        properties.setProperty("metadata,broker.list","cj.sun.hadoop1:9092,cj.sun.hadoop1:9092");
        properties.setProperty("serializer.class","kafka.serializer.StringEncoder");

        //获取配置，当然也可以把server.properties 放在根路径下
        ProducerConfig producerConfig = new ProducerConfig(properties);


        Producer<String, String> producer = new Producer(producerConfig);

        //发送业务消息
        //读取文件 读取数据库 读取socker端口
        for(int i= 1;i<=1000;i++){
            Thread.sleep(500);
            producer.send((Seq<KeyedMessage<String, String>>) new KeyedMessage("mygirls","when i see you ,i thought love you deeply"));
        }

    }

}
